package com.followmeandroid;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;

import com.followmeandroid.models.Member;

import java.util.UUID;

/**
 * <p>Title: SettingActivity</p>
 * <p>Description: This activity controls the content and
 * functionality of the Settings screen.</p>
 * @team Adam Drews
 * @email adam.drews@my.uwrf.edu
 * @team Tyler Johnson
 * @email tyler.johnson@my.uwrf.edu
 * @team Nicholas Thorp
 * @email nicholas.thorp@my.uwrf.edu
 * @date 11/17/2014
 */
public class SettingsActivity extends Activity {

    private Switch locationShareSwitch;

    /**
     * Creates the layout for the current view. It is passed a
     * bundle of data from the previous activity.
     * @param savedInstanceState        The state of the previous activity.
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);

        locationShareSwitch = (Switch) findViewById(R.id.shareSwitch);
        //Test user for now, just to prove functionality
        final Member a = new Member(UUID.randomUUID(), "test", "tester");
        //set the position of the share switch
        locationShareSwitch.setChecked(a.getWillShareLocation());

        //attach a listener to check for changes in state
        locationShareSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            /**
             * Changes the sharing location state of the user when the
             * slider is clicked.
             * @param buttonView        The current button.
             * @param isChecked         The buttons position state.
             */
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {

                if (isChecked) {
                    a.shareLocation();
                } else {
                    a.unShareLocation();
                }

                System.out.println("Share result " + a.getWillShareLocation());

            }
        });

    }

    /**
     * Creates the options menu.
     * @param menu      The menu to display.
     * @return true     Success!
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_settings, menu);
        return true;
    }

    /**
     * Controls what actions to take when an option in the options
     * menu is clicked.
     * @param item          The item that was selected.
     * @return  true        Success!
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
